﻿using System.ComponentModel;
using System.Reflection;

namespace TDM.WebBiz.Common
{

    public enum ResultFileType
    {
        /// <summary>
        /// 除锈等级
        /// </summary>
        [Description("除锈等级")]
        CleanLevel = 1,
        /// <summary>
        /// 水溶性盐浓度
        /// </summary>
        [Description("水溶性盐浓度")]
        SaltConcentration = 2,
        /// <summary>
        /// 粗糙度
        /// </summary>
        [Description("粗糙度")]
        Roughness = 3,
        /// <summary>
        /// 油漆种类及附着力
        /// </summary>
        [Description("油漆种类及附着力")]
        PaintType = 4,
        /// <summary>
        /// 表面元素成分变化
        /// </summary>
        [Description("表面元素成分变化")] SurfaceChange = 5,
        /// <summary>
        /// 宏观形貌-清理前
        /// </summary>
        [Description("宏观形貌-清理前")] MorphologyBefore = 6,
        /// <summary>
        /// 宏观形貌-清理后
        /// </summary>
        [Description("宏观形貌-清理后")] MorphologyAfter = 7,
        /// <summary>
        /// 微观形貌
        /// </summary>
        [Description("微观形貌")] MicroMorphology = 8,
        /// <summary>
        /// 微观组织
        /// </summary>
        [Description("微观组织")] Microstructure = 9,
        /// <summary>
        /// 表面硬度
        /// </summary>
        [Description("表面硬度")] SurfaceHardness = 10,
        /// <summary>
        /// 拉伸性能
        /// </summary>
        [Description("拉伸性能")] StretchingPerform = 11,
        /// <summary>
        /// 抗冲击性能
        /// </summary>
        [Description("抗冲击性能")] ImpactPerform = 12,
        /// <summary>
        /// 备注
        /// </summary>
        [Description("备注")] Remark = 13
    }

    /// <summary>
    /// 作业方式枚举
    /// </summary>
    public enum BCDType
    {
        [Description("复合")]
        Complex = 0,
        [Description("便携")]
        Portable = 1
    }

    /// <summary>
    /// 任务文件类型
    /// </summary>
    public enum TaskFileType
    {
        /// <summary>
        /// 任务场景图片
        /// </summary>
        Img = 0,
    }

    /// <summary>
    /// 枚举扩展类
    /// </summary>
    public static class EnumExtension
    {
        public static string GetDescription(Enum enumValue)
        {
            if (enumValue == null)
                throw new ArgumentNullException(nameof(enumValue));

            // 获取枚举值对应的成员信息
            MemberInfo[] memberInfo = enumValue.GetType().GetMember(enumValue.ToString());
            if (memberInfo.Length == 0)
                return enumValue.ToString(); // 成员不存在时返回默认名称

            // 获取成员上的DescriptionAttribute特性
            DescriptionAttribute[] attributes = memberInfo[0]
                .GetCustomAttributes(typeof(DescriptionAttribute), inherit: false)
                .Cast<DescriptionAttribute>()
                .ToArray();

            // 如果存在Description特性，返回其值；否则返回枚举名称
            return attributes.Length > 0 ? attributes[0].Description : enumValue.ToString();
        }

        //// 泛型版本（更类型安全）
        //public static string GetDescription<T>(T enumValue) where T : Enum
        //{
        //    return GetDescription(enumValue as Enum);
        //}
    }
}
